
#include <iostream>
#include <string>
#include <math.h>
#include "vector4.h"
#include "matrix44.h"


Vector4::Vector4( ) {
	_v[0] = _v[1] = _v[2] = 0.f;
	_v[3] = 1.f;
} Vector4::Vector4(float x, float y, float z) {
	_v[0] = x;
	_v[1] = y;
	_v[2] = z;
	_v[3] = 1.f;
} Vector4::Vector4(float x, float y, float z, float w) {
	_v[0] = x;
	_v[1] = y;
	_v[2] = z;
	_v[3] = w;
}
 Vector4::Vector4(Vector4 *u) {
	_v[0] = u->get(0);
	_v[1] = u->get(1);
	_v[2] = u->get(2);
	_v[3] = u->get(3);
}

void Vector4::operator=(Vector4 v)
{
	this->_v[0] = v[0];
	this->_v[1] = v[1];
	this->_v[2] = v[2];
	this->_v[3] = v[3];
}
Vector4 Vector4::operator+(Vector4 v)
{
	Vector4 add = Vector4();
	add.setX(v[0]+_v[0]);
	add.setY(v[1]+_v[1]);
	add.setZ(v[2]+_v[2]);
	return add;
}
Vector4 Vector4::plus(Vector4 v)
{
	Vector4 add = Vector4();
	add.setX(v[0]+_v[0]);
	add.setY(v[1]+_v[1]);
	add.setZ(v[2]+_v[2]);
	return add;
} Vector4 *Vector4::plus(Vector4 *v)
{
	Vector4 *add = new Vector4();
	add->setX(v->get(0)+_v[0]);
	add->setY(v->get(1)+_v[1]);
	add->setZ(v->get(2)+_v[2]);
	return add;
}

Vector4 Vector4::operator-(Vector4 v)
{
	Vector4 sub = Vector4();
	sub.setX(_v[0]-v[0]);
	sub.setY(_v[1]-v[1]);
	sub.setZ(_v[2]-v[2]);
	return sub;
}
Vector4 Vector4::operator-(Vector4 *v)
{
	Vector4 sub = Vector4();
	sub.setX(_v[0]-v->get(0));
	sub.setY(_v[1]-v->get(1));
	sub.setZ(_v[2]-v->get(2));
	return sub;
}
Vector4 Vector4::minus(Vector4 *v)
{
	Vector4 sub = Vector4();
	sub.setX(_v[0]-v->get(0));
	sub.setY(_v[1]-v->get(1));
	sub.setZ(_v[2]-v->get(2));
	return sub;
}
Vector4 Vector4::operator*(float s)
{
	Vector4 v = Vector4(_v[0], _v[1], _v[2]);
	v.scale(s);
	return v;
}

// Scale vector by s
void Vector4::scale(float s)
{
	for(int i=0; i<3; i++)
		_v[i] *= s;
}

float Vector4::modulus(){
	return sqrt(_v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2]);
}

void Vector4::normalize()
{

	float len = modulus();
	_v[0] /= len;
	_v[1] /= len;
	_v[2] /= len;
}


void Vector4::reset()
{
	this->_v[0] = 0.f;
	this->_v[1] = 0.f;
	this->_v[2] = 0.f;
	this->_v[3] = 0.f;
}

float Vector4::dot(Vector4 v)
{
	return (_v[0] * v[0]) + // x1*x2
		   (_v[1] * v[1]) + // y1*y2
		   (_v[2] * v[2]) + // z1*z2
		   (_v[3] * v[3]);  // w1*w2
}
float Vector4::dot(float v[4])
{
	return (_v[0]*v[0]) + // x1*x2
		   (_v[1]*v[1]) + // y1*y2
		   (_v[2]*v[2]) + // z1*z2
		   (_v[3]*v[3]);  // w1*w2
}

Vector4 Vector4::cross(Vector4 u){
	return Vector4((_v[1]*u[2])-(_v[2]*u[1]),
		           (_v[2]*u[0])-(_v[0]*u[2]),
				   (_v[0]*u[1])-(_v[1]*u[0]));
}

Vector4 Vector4::cross(float u[4]){
	return Vector4((_v[1]*u[2])-(_v[2]*u[1]),
		           (_v[2]*u[0])-(_v[0]*u[2]),
				   (_v[0]*u[1])-(_v[1]*u[0]));
}


